package com.loan.controller;

import com.loan.entity.Measure;
import com.loan.service.AvaloanService;
import com.loan.service.MeasureService;
import com.loan.utils.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * @author z
 */
@Api(tags = "测额管理")
@RestController
@RequestMapping("/measure")
public class MeasureController {

    @Resource
    private MeasureService measureService;
    @Resource
    private AvaloanService avaloanService;

    @ApiOperation(value = "贷款测额人数显示",httpMethod = "GET",notes = "显示贷款测额总人数")
    @GetMapping("/getAll")
    public ResponseResult<Integer> getAllMeasure(){
        int count = measureService.count();
        return ResponseResult.success(count);
    }
    @ApiOperation(value = "添加贷款测额表",httpMethod = "POST",notes = "添加贷款测额表")
    @PostMapping("/addMeasure")
    public ResponseResult<?> addMeasure(@RequestBody Measure measure){
        //获取房屋总价
        BigDecimal total = measure.getTotal();
        //获取可贷额度
        BigDecimal avLoan = avaloanService.getAvLoan(total);
        measureService.addMeasure(measure);
        return ResponseResult.success(avLoan);
    }
}
